package com.zhuanzhuan.hero.user.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @ClassName UserStateEnum
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/18 11:17
 */
@Getter
public enum UserStateEnum {
    WAIT_SETTLE(10, "待入驻"),
    SETTLED(20, "已入驻"),
    EXITED(30, "已退出"),
    EXPELLED(40, "已清退"),
    EXPIRED(50, "已过期"),

    UNREGISTERED(100, "已注销"),
    ;

    private final Integer code;

    private final String name;

    UserStateEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(Integer code) {
        if (Objects.isNull(code)) {
            throw new IllegalArgumentException();
        }
        return Arrays.stream(UserStateEnum.values())
            .filter(anEnum -> code.equals(anEnum.getCode()))
            .findFirst()
            .orElseThrow(RuntimeException::new)
            .getName();
    }
}
